using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 易伤Buff - 增加目标受到的伤���
/// </summary>
public class VulnerabilityBuff : BuffBase
{
    private float m_DamageMultiplier;
    private float m_OriginalDamageMultiplier = 1.0f;

    public VulnerabilityBuff(BuffData buffData, Entity caster, Entity target) : base(buffData, caster, target)
    {
        if (buffData is VulnerabilityData vulnData)
        {
            m_DamageMultiplier = vulnData.DamageMultiplier;
        }
        else
        {
            m_DamageMultiplier = 1.5f; // 默认增加50%伤害
        }
    }

    protected override void OnStart()
    {
        base.OnStart();
        
        // 设置伤害倍率
        // 这里需要根据具体的伤害系统来实���
        // Target.SetDamageMultiplier(m_DamageMultiplier);
        
        // 播放易伤特效
        if (BuffData.Effect != null)
        {
            var effect = GameObject.Instantiate(BuffData.Effect, Target.transform);
            effect.transform.localPosition = Vector3.zero;
        }
        
        // 设置动画状���
        if (Target.Animator != null)
        {
            Target.Animator.SetBool("vulnerable", true);
        }
        
        Logger.Log("VulnerabilityBuff", $"{Target.name} 变得易伤，受到的伤害增加 {m_DamageMultiplier * 100}%");
    }

    protected override void OnTick(float dt)
    {
        base.OnTick(dt);
        // 易伤期间不需要特殊处���
    }

    protected override void OnFinish()
    {
        base.OnFinish();
        Logger.Log("VulnerabilityBuff", $"{Target.name} 易伤效果结束");
    }

    protected override void OnRemove()
    {
        base.OnRemove();
        
        // 恢复原始伤害倍率
        // Target.SetDamageMultiplier(m_OriginalDamageMultiplier);
        
        // 恢复动画状���
        if (Target.Animator != null)
        {
            Target.Animator.SetBool("vulnerable", false);
        }
        
        // 清理特效
        var effects = Target.GetComponentsInChildren<ParticleSystem>();
        foreach (var effect in effects)
        {
            if (effect.name.Contains("Vulnerability"))
            {
                GameObject.Destroy(effect.gameObject);
            }
        }
    }

    public override bool IsCanMerge()
    {
        return true; // 易伤效果可以叠加，刷新持续时���
    }
}
